package com.gitee.yusugar.core.task.enums;

import cn.hutool.core.date.DateUtil;

import java.util.Arrays;

/**
 * 日期格式枚举
 *
 * @author Y.sugar
 * @since 2023/7/25 11:04
 */
public enum TimerStrType {

    y(DateUtil.thisYear(), 2300, 0),
    M(1, 12, 1),
    d(1, 31, 2),
    h(0, 23, 3),
    m(0, 59, 4),
    s(0, 59, 5),
    w(1, 7, 6);

    public Integer min;
    public Integer max;
    public Integer type;

    /**
     * 构造函数
     *
     * @param min  最小值
     * @param max  最大值
     */
    TimerStrType(Integer min, Integer max, Integer type) {
        this.min = min;
        this.max = max;
        this.type = type;
    }

    public static TimerStrType find(int type) {
        TimerStrType[] values = TimerStrType.values();
        try {
            return Arrays.stream(values).filter(timerStrType -> timerStrType.type.equals(type)).findFirst().orElse(null);
        } catch (IllegalArgumentException e) {
            return null;
        }
    }
}
